LiteLFG = {
	Frame = {},
	Locale = {},
}

local Frame = LiteLFG.Frame
local Locale = LiteLFG.Locale

local print = function (msg)
	DEFAULT_CHAT_FRAME:AddMessage(tostring(msg or "nil"));
end

function LiteLFG.Init()
	LiteLFG.CreateButtonsOnLFGFrame();
	LiteLFG.SetTextToButton();
	print("Lylandris' " .. LiteLFGAddon.Name .. LiteLFGAddon.Version .. " loaded!");
end

function LiteLFG.CreateButtonsOnLFGFrame()
	Frame.pLFGWizardFrame = CreateFrame("Button", nil, LFGWizardFrame, "UIPanelButtonTemplate");
	Frame.pLFGWizardFrame:SetWidth(110);
	Frame.pLFGWizardFrame:SetHeight(22);
	Frame.pLFGWizardFrame:SetPoint("TOPRIGHT", "LFGWizardFrame", "TOPRIGHT", -50, -45);
	Frame.pLFGWizardFrame:SetScript("OnClick", function() LiteLFG.ToggleLFGChannel(); HideUIPanel(LFGParentFrame); end);

	Frame.pLFGFrame = CreateFrame("Button", nil, LFGFrame, "UIPanelButtonTemplate");
	Frame.pLFGFrame:SetWidth(110);
	Frame.pLFGFrame:SetHeight(22);
	Frame.pLFGFrame:SetPoint("TOPRIGHT", "LFGFrame", "TOPRIGHT", -50, -45);
	Frame.pLFGFrame:SetScript("OnClick", function() LiteLFG.ToggleLFGChannel(); HideUIPanel(LFGParentFrame); end);

	Frame.pLFMFrame = CreateFrame("Button", nil, LFMFrame, "UIPanelButtonTemplate");
	Frame.pLFMFrame:SetWidth(110);
	Frame.pLFMFrame:SetHeight(22);
	Frame.pLFMFrame:SetPoint("TOPRIGHT", "LFMFrame", "TOPRIGHT", -50, -45);
	Frame.pLFMFrame:SetScript("OnClick", function() LiteLFG.ToggleLFGChannel(); HideUIPanel(LFGParentFrame); end);
end

function LiteLFG.SetTextToButton()
	local _, _, _, _, _, _, _, _, _, _, lfgStatus, lfmStatus = GetLookingForGroup();
	if (lfgStatus or lfmStatus) then
		Frame.pLFGWizardFrame:SetText(Locale.LITELFG_LEAVEBUTTON);
		Frame.pLFGFrame:SetText(Locale.LITELFG_LEAVEBUTTON);
		Frame.pLFMFrame:SetText(Locale.LITELFG_LEAVEBUTTON);
	else
		Frame.pLFGWizardFrame:SetText(Locale.LITELFG_JOINBUTTON);
		Frame.pLFGFrame:SetText(Locale.LITELFG_JOINBUTTON);
		Frame.pLFMFrame:SetText(Locale.LITELFG_JOINBUTTON);
	end
end


function LiteLFG.ToggleLFGChannel()
	local _, _, _, _, _, _, _, _, _, _, lfgStatus, lfmStatus = GetLookingForGroup();
	if (lfgStatus) then
		ClearLookingForGroup();
		return;
	end
	if (lfmStatus) then
		ClearLookingForMore();
		return;
	end
	if ((GetRealNumPartyMembers() == 0) and (GetRealNumRaidMembers() == 0)) then
		ClearLookingForGroup();
		SetLookingForGroup(3,5,1);
		ClearLFGAutojoin();
	elseif ((GetRealNumPartyMembers() > 0) or (GetRealNumRaidMembers() > 0)) then
		ClearLookingForMore();
		SetLookingForMore(5,1);
		ClearLFMAutofill();
	end
	SetLFGComment(Locale.LITELFG_LFG_COMMENT);
end


